<template>
  <div>
    <div class="user-info-head">
      <image-upload @setImageUrl="setImageUrl" :limit="1" :file-size="5" v-model="user.avatar"/>
    </div>
  </div>
</template>

<script>
import store from "@/store";
import { updateUserProfile, uploadAvatar } from '@/api/system/user'


export default {
  components: {},
  props: {
    user: {
      type: Object
    }
  },
  data() {
    return {};
  },
  methods: {
    setImageUrl(url) {
      const userInfo = { avatar: url }
      updateUserProfile(userInfo).then(response => {
        this.$set(this.user, 'avatar', url);
        store.commit('SET_AVATAR', url);
        this.$modal.msgSuccess("修改成功");
      });
    }
  }
};
</script>
<style scoped lang="scss">
.user-info-head {
  position: relative;
  display: inline-block;
  height: 120px;
}
</style>
